//
//  USEmptyView.m
//  us
//
//  Created by karry on 2025/4/21.
//

#import "USEmptyView.h"

@interface USEmptyView()

@property (nonatomic,strong)UIImageView *imageView;
@property (nonatomic,strong)UILabel *titleLabel;

@end

@implementation USEmptyView

#pragma mark - 初始化

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
    }
    return self;
}

#pragma mark - 懒加载子视图

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
    }
    return _imageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
        _titleLabel.textColor = UIColor.darkGrayColor;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UIButton *)btn {
    if (!_btn) {
        _btn = [UIButton buttonWithType:UIButtonTypeSystem];
        _btn.tintColor = UIColor.blackColor;
        UIButtonConfiguration *config = [UIButtonConfiguration filledButtonConfiguration];
        config.cornerStyle = UIButtonConfigurationCornerStyleCapsule;
        config.title = self.btnTitle;
        config.contentInsets = NSDirectionalEdgeInsetsMake(8, 20, 8, 20);
        _btn.configuration = config;
        [self addSubview:_btn];
    }
    return _btn;
}

#pragma mark - 属性设置

- (void)setImage:(UIImage *)image {
    _image = image;
    self.imageView.image = image;
    [self setNeedsLayout];
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
    [self setNeedsLayout];
}

- (void)setBtnTitle:(NSString *)btnTitle {
    _btnTitle = btnTitle;
    UIButtonConfiguration *config = self.btn.configuration;
    config.title = btnTitle;
    self.btn.configuration = config;
    [self setNeedsLayout];
}

#pragma mark - 布局子视图

- (void)layoutSubviews {
    [super layoutSubviews];
        
    [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(20);
        make.centerX.mas_equalTo(self);
        make.bottom.mas_equalTo(self.titleLabel.mas_top).mas_offset(-20);
    }];

    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(30);
        make.right.mas_offset(-30);
        make.centerY.mas_equalTo(self);
    
    }];
    
    [self.btn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(20);
        make.bottom.mas_offset(-20).priority(250);
    }];
    
    
}

@end
